package com.example.controller;

import com.example.common.Result;
import com.example.entity.AdminNotice;
import com.example.service.NoticeService;
import com.mysql.cj.protocol.x.Notice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {
    @Resource
    NoticeService noticeService;
            @GetMapping("/getAll")
    public Result getAll(@RequestParam(defaultValue = "1") Integer id, AdminNotice adminNotice){
           List<AdminNotice> noticeList = noticeService.getAll(adminNotice);
           return Result.success(noticeList);
            }
            @PostMapping("/add")
    public  Result add(@RequestBody AdminNotice adminNotice){
                if(adminNotice.getContent()==null){
                    return Result.error("增添通知不能为空");
                }
                noticeService.add(adminNotice);
                return  Result.success();
            }
            @PutMapping("/update")
    public  Result update(@RequestBody AdminNotice adminNotice){
                noticeService.update(adminNotice);
                return  Result.success();
            }
            @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
                noticeService.delete(id);
                return Result.success();
            }
}
